package cn.sxt.service.impl;

import cn.xbtop.domain.UserAddress;
import cn.xbtop.service.UserService;
import com.alibaba.dubbo.config.annotation.Service;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Mxb
 * @version 1.0
 * @date 2020/5/7 20:56
 */
// 修改权重（默认100）
@Service(weight = 200)  //暴露服务
public class UserServiceImpl implements UserService {

    public static List<UserAddress> list = new ArrayList<>();

    static {
        list.add(new UserAddress(20880,"提供者","port"));
        list.add(new UserAddress(1, "新乡", "xy"));
        list.add(new UserAddress(2, "郑州", "zz"));
        list.add(new UserAddress(2, "平顶山", "pds"));
    }

    @HystrixCommand
    @Override
    public List<UserAddress> queryAllAddress(String userId) {
        //模拟50%出现服务异常
        if(Math.random() < 0.5){
            throw new RuntimeException("服务异常。。。");
        }
        System.out.println(userId);
        return list;
    }
}
